import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../components/login.vue'
import home from '../components/home.vue'
import Welcome from '../components/SystemHomePage/Welcome.vue'
import AdministratorInformation from '../components/Users/AdministratorInformation.vue'
import HousingInformationManagement from '../components/Users/HousingInformationManagement.vue'
import AdvanceOrderManagement from '../components/Users/AdvanceOrderManagement.vue'
import OnlineHelpManagement from '../components/Users/OnlineHelpManagement.vue'
import HousingInformation from '../components/House/HousingInformation.vue'
import AnnouncementInformation from '../components/Announcement/AnnouncementInformation.vue'
import UserQuestions from '../components/OnlineHelp/UserQuestions.vue'
import SearchFunction from '../components/Search/SearchFunction.vue'

Vue.use(VueRouter)

const router = new VueRouter({
  routes : [
    {path:'/',redirect: '/login'},
    {path:'/login',component: login},
    {
      path:'/home',
      component: home,
      redirect:'/SystemHomePage',
      children:[
        {path:'/SystemHomePage',component:Welcome},
        {path:'/AdministratorInformation',component:AdministratorInformation},
        {path:'/HousingInformationManagement',component:HousingInformationManagement},
        {path:'/AdvanceOrderManagement',component:AdvanceOrderManagement},
        {path:'/OnlineHelpManagement',component:OnlineHelpManagement},
        {path:'/HousingInformation',component:HousingInformation},
        {path:'/AnnouncementInformation',component:AnnouncementInformation},
        {path:'/UserQuestions',component:UserQuestions},
        {path:'/SearchFunction',component:SearchFunction},
      ]
    },
  
  ]
})
//路由守卫
router.beforeEach((to, from, next) => {
    //{to and from are Route Object,next() must be called to resolve the hook}
    if(to.path==='/login') return next();
    const tokenStr = window.sessionStorage.getItem('LoginToken')
    if(!tokenStr) return next('/login')
    next()
  
})

export default router
